package com.ruoyi.web.controller.greatWall;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtil;
import com.ruoyi.system.domain.greatWall.Exp;
import com.ruoyi.system.service.ExpService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zxy
 * @date 2022/2/28 11:06
 */
@RestController
@RequestMapping(value = "gwExp")
public class ExpController extends BaseController {

    @Autowired
    private ExpService service;

    @PutMapping
    public Exp save(@RequestBody Exp exp){
        if (StringUtils.isEmpty(exp.getCreateDate())){
            exp.setCreateDate(DateUtil.getNowTime());
        }else {
            exp.setUpdateDate(DateUtil.getNowTime());
        }
        service.saveOrUpdate(exp);
        return exp;
    }


    @DeleteMapping(value ="{id}")
    public void delete(@PathVariable String id){
        service.removeById(id);
    }

    @GetMapping(value = "list")
    public TableDataInfo page(Exp exp){
       return getDataTable(service.pageSearch(exp));
    }

    @GetMapping(value = "{id}")
    public AjaxResult getById(@PathVariable String id){
        Exp exp = service.getById(id);
        return success(exp);
    }

}
